package com.czc.controller;

import com.czc.service.HystrixPaymentService;


import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")  //配置全局降级服务方法。
public class HystrixOrderController {

    @Resource
    private HystrixPaymentService hystrixPaymentService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = hystrixPaymentService.paymentInfo_OK(id);
        return result;
    }
    @GetMapping("/consumer/payment/hystrix/error/{id}")
    /*@HystrixCommand(fallbackMethod = "paymentInfo_ErrorFallbackMethod",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    })*/
    @HystrixCommand  //没有上面指定的fallbackMethod 就会使用defaultFallback全局降级的服务方法
    public String paymentInfo_Error(@PathVariable("id") Integer id){
        String result = hystrixPaymentService.paymentInfo_ERROR(id);
        return result;
    }

    //降级的方法
    public String paymentInfo_ErrorFallbackMethod(@PathVariable("id") Integer id){
        return "我是消费者80，对付支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,(┬＿┬)";
    }

    //下面是全局fallback方法,没有指定fallbackMethod方法 就会使用全局策略
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息,请稍后再试 -_-||";
    }

}
